const {ploads}=require('../utils/cos')
const fs=require('node:fs')
const serviceSql=require('../service/service')

class fileController{
    async read(ctx,next){
        const {filename,mimetype,size} = ctx.avatarInfo
        const {id}=ctx.tokenInfo
        let img = await ploads(filename)
        fs.unlinkSync('uploads/'+filename)
        await serviceSql.userUpdata(id,img)
        await serviceSql.fileInse(img,mimetype,size,id)
        ctx.mesg="上传成功"
        ctx.body=[]

        await next()
    }
}

module.exports=new fileController()